<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增栏目')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-cloumn-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">栏目名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
            <label class="col-sm-3 control-label">栏目状态：</label>
            <div class="col-sm-8">
                <label class="toggle-switch switch-solid">
                    <input type="checkbox" id="status" checked>
                    <span></span>
                </label>
            </div>
        </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上级栏目：</label>
                <div class="col-sm-8">
                    <select id="post" class="form-control" required>
                        <option  value="0"  >一级栏目</option>
                       <!-- <option  value="0"  style="display: none">一级栏目</option>-->
                        <option th:each="cloumn:${cloumns}" th:value="${cloumn.id}" th:text="${cloumn.name}" ></option>
                    </select>
                </div>
            </div>
             <!--   <div class="form-group">
                    <label class="col-sm-3 control-label">专题图片：</label>
                    <div class="col-sm-8">
                        <input type="file" id="files" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"  >
                        <input  id="filesurl"  name="url"  type="hidden" >
                        <img src="" alt="" id="img" style="width:300px;height:200px">
                        &lt;!&ndash;<div id="imgList" style="margin-top:10px"></div>&ndash;&gt;
                    </div>
                </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">排序：</label>
                <div class="col-sm-8">
                    <input name="sortpath" class="form-control" type="number" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/cloumn"
        $("#form-cloumn-add").validate({
            focusCleanup: true
        });
        $("#files").on("change", function() {
            var data = new FormData();
            data.append("file", this.files[0]);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                async:false,
                success: function(result) {
                    console.log(result)
                    if (result.code == web_status.SUCCESS) {
                        var url = result.url;
                        console.log(typeof(url))
                        $("#filesurl").val(url)
                        $("#img").attr("src",url);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        })
        function submitHandler() {
            if ($.validate.form()) {
                var pid = $.form.selectSelects("post");
                var data = $("#form-cloumn-add").serializeArray();
                var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
                data.push({"name": "status", "value": status});
                data.push({"name": "pid", "value":pid});
                $.operate.save(prefix + "/add", data);
            }
        }
    </script>
</body>
</html>